{% extends 'base.html' %}
{% block content %}

<a href="/forum/">Forum</a> <b>></b> <a href="/forum/{{ forum.id }}/">{{forum.title}}</a> <b>></b> {{thread.title}}

<br>
{% if thread.getForumPosts %}
    <table border = 1>
    {% for forumpost in thread.getForumPosts %}
    <tr>
        <td width = 200>{{ forumpost.author }} <br> {{ forumpost.datePosted }}</td>
        {% if forumpost.deleted %}
        <td> Post deleted by {{ forumpost.editor }} on {{ forumpost.dateEdited }} </td>
        {% else %}
        <td width = 600>{{ forumpost.body }}
        {% if forumpost.editor %}
            <br><i>Edited by {{ forumpost.editor }} on {{forumpost.dateEdited }}</i>
            {% endif %}
            </td>
        {% if not thread.locked %}
        <form action="" method="post">
            {% csrf_token %}
            {% if user.is_staff %}
                <td> <input type="submit" name="delete_forumpost" value="Delete" /></td>
            {% endif %}
            {% if user.is_staff or user == forumpost.author %}
                <td><input type="submit" name="edit_forumpost" value="Edit" /></td>
            {% endif %}
            <input type="hidden" name="forumpost" value= {{ forumpost.id }} />
        </form> 
        {% endif %}
    {% endif %}
    </tr>
    {% endfor %}
    </table>
{% else %}
    <p>No posts in this thread, somehow...</p>
{% endif %}
{% if thread.locked %}
    Thread is locked.
{% else %}
{% if user.is_authenticated %}
        <a href="/forum/{{ forum.id }}/{{ thread.id }}/new">New Post</a>
    {% else %}
    <a href='/accounts/login/'>You must be logged in to post in the forums.</a>
    {% endif %}
    {% endif %}
{% endblock %}